package com.feixiang.feixiangagent.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * 向量数据库初始化(基于内存Bean)
 */
@Configuration
public class LoveAppVectorStoreConfig {
    @Resource
    private LoveAppDocumentLoader loveAppDocumentLoader;
    @Resource
    private MyTokenTextSplitter  myTokenTextSplitter;
    @Resource
    private
    MyKeywordEnricher myKeywordEnricher;
    @Bean
    VectorStore loveAppVectorStore(EmbeddingModel dashscopeEmbeddingModel){
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(dashscopeEmbeddingModel).build();
        //加载文档
        List<Document> documents = loveAppDocumentLoader.loadMarkdowns();
        //自主切割
        //List<Document> splitDocuments = myTokenTextSplitter.splitDocuments(documents);
        //simpleVectorStore.add(splitDocuments);
        //利用添加原元信息
        List<Document> enricheDocuments = myKeywordEnricher.enrichDocuments(documents);
        simpleVectorStore.add(enricheDocuments);
        return simpleVectorStore;
    }
}
